
import router from './index'


router.beforeEach((to,from,next)=>{
   var user = sessionStorage.getItem('userInfo')
   
   const path = to.matched.some(record=> record.path)
   //登录页放行
    if( path === '/' || !path){
        next()
        return
    }
    //没有Authorization，拦截，回到登录页
    if(!sessionStorage.getItem('Authorization') ){
        next({
            path:'/'
        })
        alert("请先登录")
       return
    }
    //登录验证通过 检查是否激活
    checkActive(user,to,next)
       
})

//检查激活
 function checkActive(user,to,next){
    const path = to.matched.some(record=> record.path)
    //放行会登录页，主要用于退出和激活后回到登录页
    if( path === '/' || !path){
        next()
        return
    }
    //检查激活
    if(!user){
        if(JSON.parse(user).user_status == 33){
            alert("请先激活")
            next({
                path:'/active'
            })
            return
        }
    }
    //有用户信息，激活检查通过，放行
    next()
   
 }